package pl.enigmatic.objects;

import java.util.HashMap;


public class PropertiesMap extends HashMap<String, Object> {

	private static final long serialVersionUID = 1L;

	public <T> T get(final Class<T> clazz, final String key) {
		if (containsKey(key)) {
			final Object value = get(key);
			if (value != null && clazz.isAssignableFrom(value.getClass())) { return clazz.cast(value); }
		}
		return null;
	}

	public byte getByte(final String key) {
		final Byte res = get(Byte.class, key);
		if (res != null) { return res; }
		return 0;
	}

	public short getShort(final String key) {
		final Short res = get(Short.class, key);
		if (res != null) { return res; }
		return 0;
	}

	public int getInteger(final String key) {
		final Integer res = get(Integer.class, key);
		if (res != null) { return res; }
		return 0;
	}

	public long getLong(final String key) {
		final Long res = get(Long.class, key);
		if (res != null) { return res; }
		return 0;
	}

	public float getFloat(final String key) {
		final Float res = get(Float.class, key);
		if (res != null) { return res; }
		return 0;
	}

	public double getDouble(final String key) {
		final Double res = get(Double.class, key);
		if (res != null) { return res; }
		return 0;
	}

	public boolean getBoolean(final String key) {
		final Boolean res = get(Boolean.class, key);
		if (res != null) { return res; }
		return false;
	}

	public char getCharacter(final String key) {
		final Character res = get(Character.class, key);
		if (res != null) { return res; }
		return '\0';
	}

	public String getString(final String key) {
		final String res = get(String.class, key);
		if (res != null) { return res; }
		return null;
	}

}
